//
//  TVRefreshGifHeader.m
//  HeFanTV
//
//  Created by bai on 16/8/12.
//  Copyright © 2016年 SAGA. All rights reserved.
//

#import "CBTRefreshGifFooter.h"

@interface CBTRefreshGifFooter()

@property (nonatomic,strong) UIView *bottomView;

@end

@implementation CBTRefreshGifFooter

#pragma mark - 重写方法
#pragma mark 基本设置
- (void)prepare
{
    [super prepare];
#pragma mark - 状态相关
    self.gifView.frame = CGRectMake(self.bounds.origin.x + 20, self.bounds.origin.y + 15, self.bounds.size.width / 2, self.bounds.size.height / 2);
    self.gifView.contentMode = UIViewContentModeScaleAspectFill;
    self.gifView.mj_w = ((CGFloat)((self.mj_w)*1.0 * ScreenNarrowSide/375));  //self.mj_w * 0.5 - 90;
    self.gifView.mj_h = ((CGFloat)((self.mj_h)*1.0 * ScreenNarrowSide/375));  //self.mj_w * 0.5 - 90;

    self.stateLabel.hidden = YES;
    self.stateLabel.font = [UIFont systemFontOfSize:13];
    self.stateLabel.textColor = UIColorFromRGB(0x969696);


    // 设置普通状态的动画图片
    NSMutableArray *idleImages = [NSMutableArray array];
    for (NSUInteger i = 0; i < 19; i++) {
         UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"headerRefresh_000%02d",(int)i]];
        [idleImages addObject:image];
    }
    [self setImages:idleImages duration:2 forState:MJRefreshStateIdle];

    //    [self setImages:idleImages forState:MJRefreshStateIdle];

    // 设置即将刷新状态的动画图片（一松开就会刷新的状态）
    NSMutableArray *refreshingImages = [NSMutableArray array];
    for (NSUInteger i = 0; i < 19; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"headerRefresh_000%02d",(int)i]];
        [refreshingImages addObject:image];
    }
    [self setImages:refreshingImages forState:MJRefreshStatePulling];

    // 设置正在刷新状态的动画图片
    [self setImages:refreshingImages forState:MJRefreshStateRefreshing];
}

-(void)setIsWelfareVC:(BOOL)isWelfareVC
{
    if (isWelfareVC) {
        [self addSubview:self.bottomView];
    }else{
        [self.bottomView removeFromSuperview];
        self.bottomView = nil;
    }
}

-(void)setState:(MJRefreshState)state
{
    [super setState:state];
    
    if (state == MJRefreshStateNoMoreData) {
        if (self.stateLabelTest != nil && self.stateLabelTest.length > 0) {
          self.stateLabel.text = self.stateLabelTest;
        }else {
        self.stateLabel.text = @"- 没有更多内容啦 - ";
        }
        self.stateLabel.hidden = NO;
        self.gifView.hidden = YES;
    }else{
         self.stateLabel.hidden = YES;
         self.gifView.hidden = NO;
    }
    
}




/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
